﻿#define _CRT_SECURE_NO_WARNINGS 1


#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    bool canPartition(vector<int>& nums)
    {
        int n = nums.size(), sum = 0;
        for (auto x : nums) sum += x;

        if (sum % 2) return false; // 如果不能平分，直接返回 false
        int aim = sum / 2; // 定义⼀下⽬标值

        vector<vector<bool>> dp(n + 1, vector<bool>(aim + 1)); // 建表
        for (int i = 0; i <= n; i++) dp[i][0] = true; // 初始化
        for (int i = 1; i <= n; i++) // 填表
            for (int j = 1; j <= aim; j++)
            {
                dp[i][j] = dp[i - 1][j];
                if (j >= nums[i - 1])
                    dp[i][j] = dp[i][j] || dp[i - 1][j - nums[i - 1]];
            }
        // 返回结果
        return dp[n][aim];
    }
};


int main()
{
    vector<int> nums = { 1,2,3,5 };


    cout << Solution().canPartition(nums) << endl;

    return 0;
}


